import Router from '@koa/router';
import { UserController } from '../../../controllers/system/userController';
import { validateDto } from '../../../middleware/validation';
import { AuthMiddleware } from '../../../middleware/authMiddleware';
import { CreateUserDto, UpdateUserDto } from '../../../dtos/system/UserDto';

const router = new Router();
const userController = new UserController();
const authMiddleware = new AuthMiddleware();

// 获取所有用户（需要认证）
router.get('/', authMiddleware.authenticate, userController.getUsers);


// 根据ID获取用户（需要认证）
router.get('/:id', authMiddleware.authenticate, userController.getUserById);

// 创建用户（需要认证，仅管理员）
router.post('/', authMiddleware.authenticate, authMiddleware.requireRole('admin'), validateDto(CreateUserDto), userController.createUser);

// 更新用户（需要认证，仅管理员）
router.put('/:id', authMiddleware.authenticate, validateDto(UpdateUserDto, { skipMissingProperties: true }), userController.updateUser);

// 删除用户（需要认证，仅管理员）
router.delete('/:id', authMiddleware.authenticate, authMiddleware.requireRole('admin'), userController.deleteUser);

export default router;